package com.shuoyue.ycgk.ui.questionbank.practice.freedom;

import com.shuoyue.ycgk.entity.Option;
import com.shuoyue.ycgk.ui.questionbank.base.BaseSimpleFragment;
import com.shuoyue.ycgk.ui.questionbank.practice.mok.MokQuestionMateralFragment;

import java.util.ArrayList;
import java.util.List;

public class FreedomSimpleFragment extends BaseSimpleFragment {
    boolean isShowRight = true;

    @Override
    protected void initView() {
        super.initView();
    }

    @Override
    protected void initData() {
        isShowRight = ((FreedomQuestionActivity) getActivity()).isShowRight;
        isShowDK = isShowRight;
        super.initData();
        changeButtonTextAndTag("下一题", 3);
    }


    protected void chooseDone() {
        super.setButtonNextText();
        super.setQuestionAnswerIsRight();
        if (isShowRight) {
            showRightAnswers();
        }
    }

    @Override
    protected void doClick(Option option) {
        if (isShowRight) {
            super.doClick(option);
        } else {
            questionSimple.setIsAnswerRight(3);//标记为已做答,未核对
            if (questionSimple.getQuestionType() == 1
            ) {
                //单选
                //改变选中状态
                if (!option.isSelect()) {//只有没有被选中的点击才改变
                    //全部变成false
                    for (Option o : questionSimple.getQuestionSimpleOptionDTOS()) {
                        o.setSelect(false);
                    }
                    //点击的变成true
                    option.setSelect(!option.isSelect());
                    //存储答案
                    List<String> selectOption = new ArrayList<>();
                    selectOption.add(option.getNo());
                    questionSimple.setMyChooseAnswer((ArrayList<String>) selectOption);
                }
                //跳转下一题
                MokQuestionMateralFragment fragment = (MokQuestionMateralFragment) getParentFragment();
                if (fragment != null) {
                    fragment.goNext();
                } else {
                    activity.goNext();
                }
            } else if (questionSimple.getQuestionType() == 3) {
                //判断
                //改变选中状态
                if (!option.isSelect()) {//只有没有被选中的点击才改变
                    //全部变成false
                    for (Option o : questionSimple.getQuestionSimpleOptionDTOS()) {
                        o.setSelect(false);
                    }
                    //点击的变成true
                    option.setSelect(!option.isSelect());
                    //存储答案
                    List<String> selectOption = new ArrayList<>();
                    selectOption.add(option.getNo());
                    questionSimple.setMyChooseAnswer((ArrayList<String>) selectOption);
                }
                //跳转下一题
                MokQuestionMateralFragment fragment = (MokQuestionMateralFragment) getParentFragment();
                if (fragment != null) {
                    fragment.goNext();
                } else {
                    activity.goNext();
                }

            } else if (questionSimple.getQuestionType() == 2) {
                //多选
                //点击后,改变选中状态
                option.setSelect(!option.isSelect());
                List<String> selectOption = new ArrayList<>();
                for (Option o : questionSimple.getQuestionSimpleOptionDTOS()) {
                    if (o.isSelect()) {
                        selectOption.add(o.getNo());
                    }
                }
                questionSimple.setMyChooseAnswer((ArrayList<String>) selectOption);

            }
            optionAdapter.notifyDataSetChanged();
            setButtonNextText();

        }
    }

}
